//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.dao.wills;

import com.aidong.dao.wills.BaseDao;
import com.aidong.model.LoginUser;
import com.aidong.model.wills.MemberInfo;
import com.aidong.service.SysUserSession;
import javax.annotation.Resource;
import org.springframework.stereotype.Repository;

@Repository
public class MemberInfoDao extends BaseDao<MemberInfo, String> {
	@Resource
	protected SysUserSession userSession;

	public MemberInfoDao() {
	}

	public MemberInfo getById(String memberCode) {
		return this.getByMemberCode(memberCode);
	}

	public MemberInfo getByMemberCode(String memberCode) {
		return (MemberInfo)this.getByWhere("memberCode=:p1", new Object[]{memberCode});
	}

	public MemberInfo getByCardCode(String cardCode) {
		MemberInfo member = (MemberInfo)this.getByWhere("cardCode=:p1", new Object[]{cardCode});
		if(member == null) {
			LoginUser user = this.userSession.getLoginUser();
			if(user != null) {
				member = (MemberInfo)this.getByWhere("cardCode=:p1", new Object[]{cardCode + user.getShopCode()});
			}
		}

		return member;
	}

	public MemberInfo getByKyogaCard(String cardCode) {
		return (MemberInfo)this.getByWhere("kyogaCard=:p1", new Object[]{cardCode});
	}

	public MemberInfo getByIdNumber(String idType, String idNumber) {
		return (MemberInfo)this.getByWhere("idType=:p1 and idNumber=:p2", new Object[]{idType, idNumber});
	}

	public MemberInfo findMember(String code) {
		return (MemberInfo)this.getByWhere("cardCode=:p1 or memberCode=:p2 or idNumber=:p3", new Object[]{code, code, code});
	}

	public void updateMemberPhoto(String memberCode, String url) {
		String sql = "update MemberInfo set memberPhoto=:p1 where memberCode=:p2";
		this.updateBySql(sql, new Object[]{url, memberCode});
	}

	public void updateIdCardPhoto(String memberCode, String url) {
		String sql = "update MemberInfo set idCardPhoto=:p1 where memberCode=:p2";
		this.updateBySql(sql, new Object[]{url, memberCode});
	}
}
